Created Spring 2021: Last updated May 18, 2021

Workshop Website

Why should I come to this workshop?

For those who don’t know anything about R

  • Learn how your organization can use R

  • Write your first R code!

  • See some highlights of the R ecosystem

Why should I come to this workshop?

For the beginner R user

  • See start-to-finish project management in R
  • Make some gorgeous plots!
  • Get super excited about next steps in your learning process
  • Make R friends
  • Python users welcome too!

Why should I come to this workshop?

For the more advanced R user

  • There is extra bonus material available for the advanced user!
  • Hear how to expand the use of R in your organization
  • Be a cheerleader to folks learning about R
  • Meet other people in Clinical Informatics using R

Wait!?! What about QI?

I didn’t forget about quality improvement!

The materials we will go through as we play with R are focused around a simulated quality improvement project to help spark your imagination about how you could use R in your work from project conception to analysis and publication.

Pre-Workshop Preparation

To Know

The workshop will be held on Zoom.

To Do

You’ll need the following during the workshop:

Extras

If you would like to some additional preparation for the workshop, I recommend the following:

  • Learn about Markdown in 10 minutes!

  • Sign up for a Github Account—free

Schedule

Introduction ~30 minutes

Systems check ~15 minutes

Play ~30 minutes

Wrap Up and Discussion ~20 minutes

What is R?

It’s a programming language.

It’s software.

It’s free!

Why is R amazing?

You can run it locally.

You can run it in the cloud.

You can run it on a high performance computing cluster!

There’s a great community around the world using R!!

Why should you add R to your workflow

You can reproduce your work.

You can share every step of your analysis.

You can reuse your code for many projects!

You can use other’s code for many projects!

What does R look like

# Text after a hash is a comment
# It is not run by the computer 
# Can be used as notes to you (or future you!)

# Here are a few simple calculations
1 + 1
## [1] 2
2 * 3
## [1] 6
4^2
## [1] 16

Text

You can manipulate strings of text.

host <- "Mara"

greeting <- "Hello World"
  
paste0(greeting, " from ", host, "!")
## [1] "Hello World from Mara!"

You can import data easily

  • Excel

  • Google Sheets

  • SAS

  • SPSS

  • Stata

  • Lot’s more

Here’s some data in Excel

You might have data like this?

Data Import Examples

How do you get it into R? Like this!

#From Excel

fake_data <- 
  read_excel("./data/qi_spreadsheet_workshop.xlsx", 
    sheet = "scatter")

Tables

You can make tables from your data.
count time resident factor_service
1 16.225 Pediatrics 0.55
2 15.675 Pediatrics 0.55
3 16.225 Pediatrics 0.55
4 11.550 Pediatrics 0.55
5 5.775 Pediatrics 0.55

Tables, behind the curtains

How did I make that table??

head(fake_data, 5) %>%
  knitr::kable() %>%
  kable_classic(full_width = F, 
                html_font = "Cambria")
count time resident factor_service
1 16.225 Pediatrics 0.55
2 15.675 Pediatrics 0.55
3 16.225 Pediatrics 0.55
4 11.550 Pediatrics 0.55
5 5.775 Pediatrics 0.55

Plots, simple

You can make plots.

Plots, statistics

You can make plots—with statistical overlay.

Plots, fancier

Plots, interactive

The code to transform the plot into an interactive plot is a single function ggplotly()!

Code + Text + Figures

With R you can create documents in different formats:

  • Word
  • PDF
  • Slides
  • Websites
  • Blogs
  • Books
  • PNG/JPEG
  • And more!!

Example of a book written in R

Book Made with R

Book Made with R

Other amazing things

You can mix programming languages together

  • R and Python

  • R and Python and SQL

  • R and Python and SQL and Bash

  • …

R is flexible!

  • You use R from start to finish with a project

  • You can use it for a single part of your project—eg making plots.

  • You can use it alongside other software like Tableau and REDCap

People know R, or want to!

  • You could hire someone to do R work for you in a day.

  • You probably already have folks at your institution who are R pros!

  • People can upskill and learn R!

Your turn now!

Systems Check

  • Log into Rstudio Cloud

  • If you don’t have a link to the materials, message Mara directly in the Zoom chat with your email

  • Raise hand in zoom if you are having trouble

  • Take this survey

  • If you are an advanced user, open up the QI_playground.Rmd and start playing around

Open up the project

Once you are in RStudio Cloud, click on the project called CIC_2021_QI_R_Workshop

RStudio Cloud

For this workshop we will be using RStudio Cloud.

Why? Because there is nothing that you need to download!

You don’t need to use RStudio to use R, but I do!

RStudio on your computer and RStudio Cloud look very similar.

R and RStudio are free to download to your computer.

RStudio Orientation: Basics

RStudio Orientation: Knit

To knit something in R means to transform it from the raw text and code into a nice output like a PDF or slides. One source material can be knit into many different outputs—from the same source I might make a website, a word document, or a set of slides.

RStudio Orientation: Create a New File

Click there to make a new file.

RStudio Orientation: Select R Markdown

Make an R Markdown Document!!

After you have selected R Markdown, you will get a pop up like below.

Title it Hello World! Hit “OK”

View the Rmd

Your new file should look something like this.

Rmd–What does it all mean?!?

An Rmd file allows you to mix code and text in a single document.

You can then knit an Rmd file to many different outputs.

YAML

The YAML header contains the special instructions on how to create the output document. We won’t do much with it here today, but it is a very powerful way to make your Rmd file as bespoke as you want it!

Code Chunks

Code chunks are where the code will go.

Code chunks have a gray background.

#This is a code chunk!
#Here is a simple calculation
1 + 2
## [1] 3

You can run a code chunk by pressing the green play button.

Text

The text areas are the white background areas below the YAML header.

You can use R Markdown syntax to generate rich text formating from simple symbols like the examples below.

Knit that R Markdown Document!!

Press the knit button.

You’ll be asked to save the file; name it hello_world

View your output

Congratulations!

Let’s start the Demo

Go to your file pane. Open the Demo.Rmd file.

Play!

Live Demo

During the workshop we will work through the Demo.Rmd.

Ask questions in the Zoom chat or raise your hand.5

Finally, the QI!

After finishing up the Demo.Rmd, we will move on to the QI part.

Finally!

Open the QI_playground.Rmd file